﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace Hallenberg.Core.IO
{
    /// <summary>
    /// A representation of a section in an INI file.
    /// </summary>
    public class IniFileSection
    {
        internal const string SectionStart = "[";
        internal const string SectionEnd = "]";
        internal const string AssignmentOperator = "=";

        /// <summary>
        /// Gets or sets the values of the current INI file section
        /// </summary>
        /// <value>The values.</value>
        public Dictionary<string, string> Values { get; private set; }

        /// <summary>
        /// Gets or sets the name of the section.
        /// </summary>
        /// <value>The name of the section.</value>
        public string SectionName { get; set; }

        /// <summary>
        /// Initializes a new instance of the <see cref="IniFileSection"/> class.
        /// </summary>
        public IniFileSection(string sectionName)
        {
            this.Values = new Dictionary<string, string>();
            this.SectionName = sectionName;
        }

        /// <summary>
        /// Add a new key/value pair to the section.
        /// </summary>
        /// <param name="key">A valid string that is not null or empty.</param>
        /// <param name="value">A valid string. Value can be empty but not null.</param>
        public void AddValue(string key, string value)
        {
            Debug.Assert(!string.IsNullOrEmpty(key));
            if (string.IsNullOrEmpty(key))
            {
                throw new ArgumentNullException("key");
            }

            // Value might be empty - it just cannot be null.

            Debug.Assert(value != null);
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            this.Values.Add(key, value);
        }
    }
}
